﻿using DevExpress.XtraEditors;
using DevExpress.XtraSplashScreen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace DotNetExtensions.AspNet.DevExpress.Services
{
    public interface IMessageService
    {
        void Show(string message);
        void Warning(string message);
        void Error(string message);
        void ShowOverlay();
        void Close();
        DialogResult Confirm(string msg);
    }

    public class DialogMessageBoxService : IMessageService
    {
        private Control OverlayControl { get; set; }
        public OverlayWindowOptions OverlayWindowOptions { get; set; }

        public DialogMessageBoxService(Control overlayControl, OverlayWindowOptions overlayWindowOptions = null)
        {
            OverlayControl = overlayControl;

            if (overlayWindowOptions != null)
            {
                OverlayWindowOptions = overlayWindowOptions;
            }
            else
            {
                OverlayWindowOptions = new OverlayWindowOptions
                {
                    BackColor = Color.FromArgb(8, 0, 0, 0),
                    FadeIn = true,
                    FadeOut = true,
                    ForeColor = Color.FromArgb(100, 60, 146, 92),
                    Opacity = 11
                };
            }
        }

        public void Show(string message)
        {
            XtraMessageBox.Show(message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public void ShowOverlay()
        {
            SplashScreenManager.ShowOverlayForm(OverlayControl, OverlayWindowOptions);
            // SplashScreenManager.ShowForm(Program.MainForm, typeof(LoadingForm), true, true);
        }

        public void Close()
        {
            SplashScreenManager.CloseForm(true);
        }

        public DialogResult Confirm(string msg)
        {
            return XtraMessageBox.Show(msg, "Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }

        public void Warning(string message)
        {
            XtraMessageBox.Show(message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }

        public void Error(string message)
        {
            XtraMessageBox.Show(message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}
